/**数据验证*/
var GLFValidator = function() {  
    var handleSubmit = function() { 
        $('.form-horizontal').validate({  
            errorElement : 'span',  
            errorClass : 'help-block',  
            focusInvalid : false,  
            rules : {  
            	"glprice" : {  
            		number : true  
                }
            },  
            messages : {  
            	"glprice"  : {  
            		number : "请输入有效的数字.例如:9.08"
                }
            },  
  
            highlight : function(element) { 
                $(element).addClass('error');  
            },  
  
            success : function(label) { 
                label.removeClass('error');  
                label.remove();
            },  
  
            errorPlacement : function(error, element) {  
            	element.parent('td').append(error);  
            },  
  
            submitHandler : function(form) {
                form.submit();
            }  
        });  
  
        $('.form-horizontal input').keypress(function(e) {  
            if (e.which == 13) {  
                if ($('.form-horizontal').validate().form()) {  
                    $('.form-horizontal').submit();  
                }  
                return false;  
            }  
        });  
    }  
    return {  
        init : function() { 
            handleSubmit(); 
        }  
    };  
  
}(); 


/**保存数据*/
function saveGLF(){
	$('#myModal').modal('show');
	
	var cidobj=$("input[@type=hidden][name=cid]");
	var ruleobj=$("select[name=glcrid]");
	var glpriceobj=$("input[@type=text][name=glprice]");
	var glcontentobj=$("input[@type=text][name=glcontent]");
	var cid="";
	var glcrid="";
	var glprice="";
	var glcontent="";

	for(var i=0;i<cidobj.length;i++){
		cid=cid+$(cidobj[i]).val()+",";
		glcrid=glcrid+$(ruleobj[i]).val()+",";
		glprice=glprice+$(glpriceobj[i]).val()+",";
		glcontent=glcontent+$(glcontentobj[i]).val()+",";
	}

	$.post("../base/saveGLF_Community.action",{"community.cid":cid,"community.glprice":glprice,"community.glcontent":glcontent,
		"community.glrule.crid":glcrid}, function(result) {
		if(result.msg=="succ"){
			$('#myModal').modal('hide');
			$("#alertinfo").html("管理费维护成功");
			$('#myinfo').modal('show');
		}else{
			$('#myModal').modal('hide');
			$("#alertinfo").html(result.msg);
			$('#myinfo').modal('show');
		}
	});
};

$(document).ready(function(){
	GLFValidator.init();
});
